package pay.config;

import o2o.cache.sys.SysConfigPayMemory;
import o2o.cache.sys.SysCustomerCache;
import o2o.dao.PO.common.ResultInfo;
import o2o.dao.PO.sys.SysConfigPay;

//初始化配置
public class PayConfig {


    public static ResultInfo init() {
        String sysAppKey = SysCustomerCache.getInstance().getDefaultKey();
        SysConfigPay sysConfigPay = SysConfigPayMemory.getInstance().getByKey(sysAppKey, "");
        if (null == sysConfigPay) {
            System.out.println("初始化支付失败");
            return new ResultInfo("初始化支付失败");
        }

        //支付标题
        Constant.PAY_SUBJECT = sysConfigPay.getPaySubject();
        Constant.PAY_CONTENT = sysConfigPay.getPayContent();

        //支付宝配置
        AlipayConfig.partner = sysConfigPay.getAliPartner();
        AlipayConfig.seller_id = sysConfigPay.getAliSellerId();
        AlipayConfig.private_key = sysConfigPay.getAliPrivateKey();
        AlipayConfig.ali_public_key = sysConfigPay.getAliPublicKey();
        AlipayConfig.app_id = sysConfigPay.getAliAppId();
        AlipayConfig.ALIPAY_GATEWAY_NEW = sysConfigPay.getAliGateway();
        AlipayConfig.notify_url = sysConfigPay.getAliNotifyUrl();
        AlipayConfig.sign_type = sysConfigPay.getAliSignType();

        //微信配置
        WeixinConfig.appid = sysConfigPay.getWxAppId();
        WeixinConfig.apiKey = sysConfigPay.getWxApiKey();
        WeixinConfig.mch_id = sysConfigPay.getWxMchId();
        WeixinConfig.notify_url = sysConfigPay.getWxNotifyUrl();
        WeixinConfig.wx_refund_cert_file_path = sysConfigPay.getWxCertFilePath();
        WeixinConfig.wx_gzh_refund_cert_file_path = sysConfigPay.getWxGzhCertFilePath();
        WeixinConfig.wx_xcx_refund_cert_file_path = sysConfigPay.getWxXcxCertFilePath();

        // 商家微信支付
        WeixinConfig.shopAppid = sysConfigPay.getWxShopAppId();
        WeixinConfig.shopApiKey = sysConfigPay.getWxShopApiKey();
        WeixinConfig.shopAppSecret = sysConfigPay.getWxShopAppSecret();
        WeixinConfig.shopMch_id = sysConfigPay.getWxShopMchId();

        // 骑手微信支付配置
        WeixinConfig.qsAppid = sysConfigPay.getWxQsAppId();
        WeixinConfig.qsApiKey = sysConfigPay.getWxQsApiKey();
        WeixinConfig.qsMch_id = sysConfigPay.getWxQsMchId();

        //公众号
        WeixinConfig.gzhAppId = sysConfigPay.getWxGzhAppId();
        WeixinConfig.gzhAppSecret = sysConfigPay.getWxGzhAppSecret();
        WeixinConfig.gzhApiKey = sysConfigPay.getWxGzhApiKey();
        WeixinConfig.gzhMchId = sysConfigPay.getWxGzhMchId();
        WeixinConfig.gzhApiNotifyUrl = sysConfigPay.getWxGzhApiKey();
        //小程序
        WeixinConfig.xcxAppId = sysConfigPay.getWxXcxAppId();
        WeixinConfig.xcxAppSecret = sysConfigPay.getWxXcxAppSecret();
        WeixinConfig.xcxMchId = sysConfigPay.getWxXcxMchId();
        WeixinConfig.xcxApiKey = sysConfigPay.getWxXcxApiKey();
        WeixinConfig.xcxApiNotifyUrl = sysConfigPay.getWxXcxApiNotifyUrl();



        System.out.println("微信证书路径：" + WeixinConfig.wx_refund_cert_file_path);

        return new ResultInfo();
    }
}
